package com.qf.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import com.qf.dao.UserDao;
import com.qf.domain.User;

public class UserDaoImpl implements UserDao{
	private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List<User> find() {
		Session session = sessionFactory.openSession();
		Query query= session.createQuery("from User");
        return query.list();
        
	}
	
	
	
	public void addUser(User u) {
      Session session=sessionFactory.openSession();
      Transaction action = session.beginTransaction();
      session.save(u);
      action.commit();
      session.close();
	}

   

}
